/**
 * Created by losor on 2017/2/25.
 */


import java.util.BitSet;

/**
 * 汉明距离
 */
public class _461_HammingDistance {
    public static void main(String[] args) {
        System.out.println(hammingDistance(1, 4));

    }

    public static int hammingDistance(int x, int y) {
        int sum = 0;
        String xs = new StringBuffer(Integer.toBinaryString(x)).reverse().toString();
        String ys = new StringBuffer(Integer.toBinaryString(y)).reverse().toString();

        int maxlength = xs.length() > ys.length() ? xs.length() : ys.length();

        for (int i = 0; i < maxlength; i++) {
            if (i < xs.length() && i < ys.length()) {
                System.out.println(xs.charAt(i)+":"+ys.charAt(i));
                if (xs.charAt(i) != ys.charAt(i)) {
                    sum++;
                }
            }
            else if (i < xs.length()){
                if (xs.charAt(i) == '1'){
                    sum++;
                }
            }
            else if (i < ys.length()){
                if (ys.charAt(i) == '1'){
                    sum++;
                }
            }
        }
        return sum;
    }

}
